-- 公会成员战功榜
local RankNormalBottomPanel = app.mvc.createPanelClass(...)
local ListViewVertical = require("app.widget.listview.ListViewVertical")

--data =
function RankNormalBottomPanel.createWithData(data, node)
    local sprite = RankNormalBottomPanel.extend(node or cc.CSLoader:createNode(Res.RankBottom))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init(data)
    return sprite
end

function RankNormalBottomPanel.create(node)
    return RankNormalBottomPanel.createWithData(nil, node)
end

function RankNormalBottomPanel:init(data)
    self.super.init(self, data)
    self._curPage = 1
    
    self._ui["Panel/Button"]:addClickEventListener(function()
        if self._data then
            executeFunc(self._onOperate, "findMyPos", self._data.otherInfo)
        end
    end)

    self._ui["Panel/Panel_page/Button_1"]:addClickEventListener(function()
        self:_onClickPageBtn(true)
    end)

    self._ui["Panel/Panel_page/Button_2"]:addClickEventListener(function()
        self:_onClickPageBtn(false)
    end)
end


function RankNormalBottomPanel:_onClickPageBtn(isLeft)
    if not self._data then
        return
    end
    local pageNum = self._data.pageNum

    if isLeft then
        if self._curPage <= 1 then
            return
        end
        self._curPage = self._curPage -1
    else
        if self._curPage >= pageNum then
            return
        end 
        self._curPage = self._curPage + 1
    end
    executeFunc(self._onOperate, "page", self._curPage)
    self._ui["Panel/Panel_page/num"]:setString(string.format("%s/%s", self._curPage, pageNum))
end


function RankNormalBottomPanel:setPage(page)
    if not self._data then
        return
    end
    local pageNum = self._data.pageNum
    if page > pageNum or page <= 0 then
        return
    end
    self._curPage = page
    self._ui["Panel/Panel_page/num"]:setString(string.format("%s/%s", self._curPage, pageNum))
end

-- executeFunc
function RankNormalBottomPanel:refresh()
    if not self._data then
        return
    end
    local data = self._data
    if data.pageNum == 0 then
        self._curPage = 0
    else
        self._curPage = 1
    end
    self._ui["Panel/Panel_page/num"]:setString(string.format("%s/%s", self._curPage, data.pageNum))
    self._ui["Panel/text"]:setString(data.myRankStr)
end


return RankNormalBottomPanel